package cn.echo.modules.sys.service;



import cn.echo.common.baseservice.BaseService;
import cn.echo.modules.sys.dao.ArticleMapper;
import cn.echo.modules.sys.dao.SiteMapper;
import cn.echo.modules.sys.dao.UserMapper;
import cn.echo.modules.sys.entity.Article;
import cn.echo.modules.sys.entity.Site;
import cn.echo.modules.sys.entity.User;
import cn.echo.modules.sys.utils.MyBatisUtils;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.session.SqlSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by V on 2017/4/13.
 */
@Service("user")
public class UserService extends BaseService {
    @Autowired
    private UserMapper userMapper;
    public List<User> findAll1(User user) {

        List<User> siteList = userMapper.findAll(new User());

        return siteList;
    }



    //用户登陆
    public int denglu(String email,String password) {

        int number = 0;
        try {
            number = userMapper.findBy(email,password);

        } catch (Exception e) {
            System.out.println("登陆失败!");
            e.printStackTrace();
            return number;
        }
        return number;
    }

    //添加用户
    public void add(User user) {

        try {
            userMapper.insert(user);
        } catch (Exception e) {
            System.out.println("添加失败!");
            e.printStackTrace();
        }
    }

    public User findById(String id) {


        return userMapper.findById(id);
    }
//更改信息
    public void update(User user) {

        try {
            userMapper.edit(user);
        } catch (Exception e) {

            e.printStackTrace();
        }

    }
//删除用户
    public void delete(User user) {

        try {

            userMapper.remove(user);
        } catch (Exception e) {

            e.printStackTrace();

        }
    }
}
